<template>
  <div class="risk">
    <eagle-page-list
      :controller="controller"
      :queryParams="queryParams"
      @bindData="bindData"
      :conditions="conditions"
      ref="eaglePageList"
    >
      <template #list>
        <div class="plan-list">
          <div
            class="plan-detail mb-10"
            v-for="(item, index) in list"
            :key="index"
            @click="handleClick(item)"
          >
            <div class="plan-detail-hd mb-10">
              <van-image
                width="50"
                height="50"
                :src="require('@/assets/Images/AppIcon/icon_exam_icon_2.png')"
              />
              <div class="mt-5">
                <div class="plan-detail-title mb-10">
                  {{ item.ExamName }}
                </div>
                <div class="plan-detail-describe">
                  {{ item.Introduce || "没有添加任何描述" }}
                </div>
              </div>
            </div>

            <div class="plan-detail-bd mt-10">
              <div>
                考试时间：{{ item.ExamStartTime }}至{{ item.ExamEndTime }}
              </div>
            </div>
            <eagle-divider />
            <div class="plan-detail-btns">
              <div v-if="item.Status == 10">
                <eagle-button
                  @click.stop="del(item)"
                  class="ml-10"
                  type="default"
                  size="small"
                  >删除</eagle-button
                >
                <eagle-button
                  @click.stop="Publish(item)"
                  class="ml-10"
                  type="default"
                  size="small"
                  >发布</eagle-button
                >
              </div>
              <div v-if="item.Status == 15">
                <eagle-button
                  @click.stop="goBack(item)"
                  class="ml-10"
                  type="default"
                  size="small"
                  >撤销</eagle-button
                >
              </div>
              <div></div>
              <div v-if="item.Status == 20">
                <eagle-button
                  @click.stop="goFollow(item)"
                  type="default"
                  size="small"
                  >跟踪</eagle-button
                >
                <eagle-button
                  @click.stop="end(item)"
                  class="ml-10"
                  type="default"
                  size="small"
                  >结束</eagle-button
                >
              </div>
              <div v-if="item.Status == 30">
                <eagle-button
                  @click.stop="goFollow(item)"
                  type="default"
                  size="small"
                  >跟踪</eagle-button
                >
              </div>
            </div>
            <eagle-tag type="success" v-if="item.Status == 15" class="tags"
              >已发布</eagle-tag
            >
            <eagle-tag type="warning" v-if="item.Status == 10" class="tags"
              >未发布</eagle-tag
            >
            <eagle-tag color="#98a4d2" v-if="item.Status == 20" class="tags"
              >进行中</eagle-tag
            >
            <eagle-tag type="primary" v-if="item.Status == 30" class="tags"
              >已结束</eagle-tag
            >
            <!-- <eagle-tag type="primary" v-if="item.Status == 30" class="tags">已结束</eagle-tag> -->
          </div>
        </div>
      </template>
    </eagle-page-list>
  </div>
</template>

<script>
import { Dialog } from "vant";
export default {
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_IMG,
      list: [],
      conditions: {},
      controller: "/ExExam",
      queryParams: {
        dataType: "MyArrangedExam",
      },
    };
  },
  // 考试详情
  // beforeRouteLeave(to, from, next) {
  // 	if (to.name == 'AddExam') {
  // 		to.meta.title = '编辑考试'
  // 	}
  // 	next() //继续下一步
  // },
  created() {},
  // mounted() {
  // 	window.history.pushState(null, null, document.URL)
  // 	window.addEventListener('popstate', this.onBrowserBack, false)
  // },
  // destroyed() {
  // 	window.removeEventListener('popstate', this.onBrowserBack, false)
  // },
  methods: {
    // onBrowserBack() {
    // 	this.$router.go(-2)
    // },
    // 搜索
    bindData(data) {
      this.list = [];
      if (data) {
        this.list = data;
      }
    },
    goFollow(item) {
      this.$router.push({
        path: "/Train/ExamFollow",
        query: { examcode: item.ExamCode },
      });
    },
    // 详情
    handleClick(item) {
      if (item.Status == 10) {
        // 编辑
        this.$router.push({
          path: "/Train/AddExam",
          query: { id: item.ID, key: "edit" },
        });
      } else {
        this.$router.push({
          path: "/Train/ExamDetail",
          query: { id: item.ID },
        });
      }
    },
    // 发布
    Publish(item) {
      const data = {
        id: item.ID,
      };
	  this.$axios
	  .get("/ExExam/Publish",{params:data})
      .then((res) => {
        this.$refs.eaglePageList.confirm();
      });
    },
    // 删除
    del(item) {
      const _this = this;
      const data = {
        id: item.ID,
      };
      Dialog.confirm({
        title: "提示",
        message: "确定删除吗？",
      })
        .then(() => {
		  _this.$axios
		  .get("/ExExam/Delete",{params:data})
          dthen((res) => {
            _this.$refs.eaglePageList.confirm();
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    goBack(item) {
      const data = {
        id: item.ID,
      };
	  this.$axios
	  .get("/ExExam/Recall",{params:data})
      .then((res) => {
        this.$refs.eaglePageList.confirm();
      });
    },
    //结束
    end(item) {
      const _this = this;
      const data = {
        id: item.ID,
      };
      Dialog.confirm({
        title: "提示",
        message: "确定结束吗？",
      })
        .then(() => {
		  _this.$axios
		  .get("/ExExam/End",{params:data})
          .then((res) => {
            _this.$refs.eaglePageList.confirm();
          });
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>
<style lang="less">
.van-field__control {
  background-color: #ffffff !important;
}
</style>
<style lang="less" scoped>
.risk {
  min-height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
  }
}
.plan-detail {
  width: 100%;
  background-color: #fff;
  border-radius: 8px;
  padding: 10px;
  color: #333;
  font-size: 10px;
  position: relative;
  .plan-detail-tag {
    position: absolute;
    top: 0;
    right: 0;
  }
}

.plan-detail-hd {
  display: flex;

  .plan-detail-title {
    font-size: 14px;
    color: #000;
  }
  span {
    color: #666;
  }
}
.exam-time {
  height: 28px;
  line-height: 28px;
  border-top: 1px solid #eee;
  border-bottom: 1px solid #eee;
}
.plan-detail-describe {
  width: 200px;
  line-height: 1.2;
  // word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
  -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  -webkit-line-clamp: 2; /** 显示的行数 **/
  overflow: hidden; /** 隐藏超出的内容 **/
  word-break: break-all;
}
.plan-detail-bd {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tags {
  position: absolute;
  top: 0px;
  right: 0;
  border-radius: 0 5px 0 5px;
}
.plan-detail-btns {
  text-align: right;
}
</style>
